//
//  SSCommonGame.h
//  SGF
//
//  Created by shanshan on 10-6-10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "SSHUD.h";
#import "SSDataManager.h"
#import "SSEntityController.h"
#import "SSEntityView.h"
#import "SSVector3D.h"
#import "SSLevel.h"

#import "SneakyJoystick.h"
#import "SneakyJoystickSkinnedJoystickExample.h"
#import "SneakyJoystickSkinnedDPadExample.h"
#import "SneakyButton.h"
#import "SneakyButtonSkinnedBase.h"
#import "ColoredCircleSprite.h"

#import "SimpleAudioEngine.h"

#define PTM_RATIO 32

@class SSGameOverLayer;

@interface SSCommonGame : CCLayer{
	
	
	int currentLevelIndex, gameScore, levelScore, livesLeft;
	SSHUD *hud;
	SSLevel *currentLevel;
	CCLayer *gameFieldLayer, *hudLayer; 
	
	SSEntityController *player;
	SSEntityView *playerView;
	
	CGPoint centerPoint;
	CGPoint viewPoint;
	
	CGSize screenSize;
	
	NSMutableArray *playerProjectiles;
	
	NSMutableArray *monsters;
	NSMutableArray *monsterProjectiles;
	NSMutableArray *escapedMonsters;
	
	
	SneakyJoystick *leftJoystick;
	SneakyButton *rightButton;
	
	SimpleAudioEngine *soundEngine;
	
	SSGameOverLayer *gameOverLayer;
}


@property (nonatomic) int currentLevelIndex, gameScore, levelScore, livesLeft;
@property (nonatomic, assign) SSHUD *hud;
@property (nonatomic, assign) SSLevel *currentLevel;
@property (nonatomic, assign) CCLayer *gameFieldLayer, *hudLayer;

@property (nonatomic, assign) CGPoint centerPoint;

@property (nonatomic, assign) CGSize screenSize;

@property (nonatomic, assign) SSEntityView *playerView;

@property (nonatomic, assign) BOOL monsterHit;
//Methods
-(id)init;
-(id)initWithLevel:(SSLevel*)level atScore:(int)score withLivesLeft:(int)lives;
-(id)initWithLevel:(SSLevel *)level haveJoystick:(BOOL)haveJoystick atScore:(int)score withLivesLeft:(int)lives;

-(void)buildLevel;

-(void)spawnEnemies:(ccTime)dt;
-(void)spawnPlayer;

-(void)buildHUD;
-(void)startLevel;
-(void)onLevelEnd;
-(void)onGameOver;

-(void)tick:(ccTime)dt;

//function to apply a velocity to a position with delta
-(void)applyJoystick:(SneakyJoystick *)aJoystick toNode:(CCNode *)aNode forTimeDelta:(float)dt;

@property(nonatomic,retain)SneakyJoystick *leftJoystick;
@property(nonatomic,retain)SneakyButton *rightButton;
@property(nonatomic,retain)NSMutableArray *monsterProjectiles;
@property(nonatomic, retain) NSMutableArray *escapedMonsters;

@property(nonatomic, retain) SimpleAudioEngine *soundEngine;

//custom methods
-(void)checkDelete:(ccTime)dt;
-(void)fire:(ccTime)dt;

-(void)updateNewPostionForPlayer;

@end
